package com.sport.controller;

import com.sport.service.IAdminService;
import com.sport.utils.JsonResult;
import com.wf.captcha.utils.CaptchaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 用来处理验证码，登陆校验
 *
 * @Author wxq
 * @Date 2021/5/10
 **/
@Controller
public class MainController {

    @Autowired
    private IAdminService adminService;

    @GetMapping("/admin/login")
    @ResponseBody
    public JsonResult adminLogin(String username, String password, String captcha, HttpSession httpSession) {
        return adminService.adminLogin(username, password, captcha, httpSession);

    }

    /**
     * 获取图形验证码(从验证码工具类中获取)
     */
    @GetMapping("/get_captcha")
    public void captcha(HttpServletRequest request, HttpServletResponse response) {
        try {
            CaptchaUtil.out(4, request, response);//输出图形验证码
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
